
import { loadSprite } from '../../Loader'
interface SetStreakParams {
  parentNode: cc.Node, // node
  resourceUrl: string,
  color?: cc.Color
}
/**
 * @description
 * @author 刘建文
 * @date 2019-12-23
 * @param {cc.Node}   param[parentNode] parentNode  添加目标节点
 * @param {string}    param[resourceUrl] 贴图资源地址
 * @param {cc.Color}  param[color] 拖尾颜色
 */
const SetStreak = async ({ parentNode, resourceUrl, color }: SetStreakParams) => {
  // cc.log(parentNode)
  const subNode = new cc.Node('streak')

  parentNode.addChild(subNode)
  const streak = subNode.addComponent(cc.MotionStreak)
  const streakRes = await loadSprite(resourceUrl, cc.SpriteFrame)
  streak.texture = streakRes
  
  streak.stroke = 5
  streak.fastMode = true
  streak.fadeTime = 0.5
  subNode.color = color || cc.color(255, 0, 0, 0.4)
  subNode.width = parentNode.width
}
export default SetStreak
